//package com.sskj.mqtt.mica;
//
//import lombok.extern.slf4j.Slf4j;
//import net.dreamlu.iot.mqtt.core.client.MqttClientCreator;
//import net.dreamlu.iot.mqtt.spring.client.event.MqttConnectedEvent;
//import net.dreamlu.iot.mqtt.spring.client.event.MqttDisconnectEvent;
//import org.springframework.context.event.EventListener;
//import org.springframework.stereotype.Service;
//
//import javax.annotation.Resource;
//
//@Slf4j
//@Service
//public class MqttClientConnectListener {
//
//    @Resource
//    private MqttClientCreator mqttClientCreator;
//
//    @EventListener
//    public void onConnected(MqttConnectedEvent event){
//        log.info("MqttConnectedEvent:{}", event);
//        log.info("Mqtt 启动成功");
//    }
//
//    @EventListener
//    public void onDisconnected(MqttDisconnectEvent event){
//        // 离线时更新重连时的密码，适用于类似阿里云 mqtt clientId 连接带时间戳的方式
//        log.info("MQtt 重连....");
//        log.info("MqttDisconnectEvent:{}", event);
//        // 在断线时更新 clientId、username、password
//        mqttClientCreator.clientId("newClient" + System.currentTimeMillis())
//                .username("admin")
//                .password("123456");
//    }
//}
